using System;
using System.Collections.Generic;
using System.Linq;
using NHibernate;
using Wikey.Domain.Components;
using Wikey.Entity;

namespace Wikey.Domain.Repository
{
    public interface IRoleRepository
    {
        int Save(Role role);
        Role Find(int? id);
        List<Role> SelectAll();
        IQueryable<Role> QueryAll();
    }

    public class RoleRepository : Repository , IRoleRepository
    {
        public RoleRepository(ISessionSource source) : base(source)
        {
        }

        public RoleRepository(ISession session) : base(session)
        {
        }

        public int Save(Role role)
        {
            base.Save(role);
            return role.Id;
        }

        public Role Find(int? id)
        {
            return Find<Role>(id.Value);
        }

        public List<Role> SelectAll()
        {
            return Context().Roles.OrderBy(t=>t.Name).ToList();
        }

        public IQueryable<Role> QueryAll()
        {
            return base.Context().Roles;
        }
    }
}